/**********************************************************************
*Created/Source by	:sfibich
*ScriptName			:metadata.function.twoPartName.sql
*Version			:1.0.120121
*Purpose			:creates a function that returns the two part object name from
*					 an object id.
**********************************************************************/
if exists (select * from sys.objects where name='twoPartName')
BEGIN
	drop function metadata.twoPartName 
END
go
create function metadata.twoPartName (@object_id int)
returns varchar(257)
as
BEGIN
declare @twoPartName varchar(257)
select 
@twoPartName=s.name+'.'+o.name
from
sys.objects o
inner join
sys.schemas s
on
o.schema_id=s.schema_id
where
o.object_id=@object_id
return (@twoPartName)
END
go

if exists (select 1 from sys.objects where name='twoPartName' and SCHEMA_NAME(schema_id)='metadata')
BEGIN
	merge metadata.utilityInfo as t
	using (
	select 
	'metadata.twoPartName' as info_desc
	,'1.0.120121' as value
	) as s
	on
	(s.info_desc=t.info_desc)
	when matched then
	update 
	set 
	t.value=s.value
	,t.date_time=getdate()
	when not matched then 
	insert
	(info_desc,value)
	values
	(s.info_desc,s.value);
END
